﻿using System;
using System.IO;
using System.Collections;
using System.Collections.Generic;

using DreamCube.WebServer.WinServiceModel;
using DreamCube.Foundation.Basic.Utility;

namespace WebServer.WinServiceManager
{
    internal abstract class Service
    {
        /// <summary>
        /// 初始状态服务是不存在的
        /// </summary>
        private MyWinService.ServiceStatus? status = MyWinService.ServiceStatus.NotExist;

        /// <summary>
        /// 服务器的状态
        /// </summary>
        public virtual MyWinService.ServiceStatus Status
        {
            get
            {
                return status.Value;
            }
        }

        /// <summary>
        /// 安装服务
        /// </summary>
        public virtual void Setup()
        {
            IDictionary result = new Hashtable();
            String exePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Common.ServiceEXEFileName);
            MyWinService.InstallService(exePath, ref result);
        }

        /// <summary>
        /// 卸载服务
        /// </summary>
        public virtual void UnInstall()
        {
            IDictionary result = new Hashtable();
            String exePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, Common.ServiceEXEFileName);
            MyWinService.UnInstallService(exePath, ref result);
        }

        /// <summary>
        /// 启动服务
        /// </summary>
        public abstract void Start();

        /// <summary>
        /// 停止服务
        /// </summary>
        public abstract void Stop();
    }
}
